﻿<%@page import="java.text.DecimalFormat"%>
<%@ page language="java" import="com.rw.table.*" import="java.util.*"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html>
<head>
<base href="<%=basePath%>">

<title>RW_b2c-cart</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">


<style type="text/css">
@import "./css/shop/header.css";

@import "./css/shop/favorite.css";
</style>


<script language="javascript" type="text/javascript"
	src="javascript/MulitiEffect.js">
	</script>


</head>

<body>

	<jsp:include flush="true" page="header.jsp"></jsp:include>
	<div class="favoriteFrame">
		<div class="favoriteEntity">
			<h2>我的收藏</h2>
			<table class="favoriteTable" border="0" cellpadding="8">
				<tr class="title">
					<td align="center" width="100px">商品名</td>
					<td align="center" width="100px">市场价</td>
					<td align="center" width="100px">会员价</td>
					<td align="center" width="100px">为您节省</td>
					<td align="center" width="100px"></td>
					<td align="center" width="70px"></td>
					<td align="center" width="70px"></td>
				</tr>
			</table>
	<%
		@SuppressWarnings("unchecked")
		List<Favoritem> favoriteList = (List<Favoritem>) request.getAttribute("favoriteInfoList");
		@SuppressWarnings("unchecked")
		List<Item> itemList = (List<Item>) request.getAttribute("favoriteItemList");
		if (favoriteList == null || itemList == null) {
	%>
	<table border="0" align="center">
		<tr>
			<td><a> </a></td>
		</tr>
		<tr>
			<td><a>没有可显示的数据</a></td>
		</tr>
	</table>
	<%
		} else {
			int t = 0;
			//分页信息
			int totalPageNum = (Integer) request.getAttribute("totalPageNum");
			int nowPage = (Integer) request.getAttribute("nowPage");
			int pageSize = (Integer) request.getAttribute("pageSize");
			String error = (String) request.getAttribute("errorMsg");
			long userId = 0;
			if (error != null) {
	%>
				<script type="text/javascript">
					alert("该商品已在收藏夹中");
				</script>
	<%
				error = null;
			}
	%>

	
			<%
				if (favoriteList != null && itemList != null) {

						Iterator<Favoritem> iterator = favoriteList.iterator();
						Iterator<Item> iterator2 = itemList.iterator();
						if (session.getAttribute("UserState") != null) {
							userId = (Long) request.getAttribute("favoriteUserId");
						}
						while (iterator.hasNext()) {
							Favoritem favorite = iterator.next();
							Item item = iterator2.next();
							long favoriteId = 0;
							if (!(session.getAttribute("UserState") == null)) {
								favoriteId = favorite.getFavoriteId();
							}
							long itemId = favorite.getFavoriteItemId();
							/**精度-小数点后两位*/
							DecimalFormat df = new DecimalFormat("#0.00");
							String marketPrice = df.format(item.getItemMarketPrice());
							String priceAfterDiscount = df.format(item.getItemMarketPrice()*item.getItemdiscount());
							String save = df.format(item.getItemMarketPrice()-(item.getItemMarketPrice()*item.getItemdiscount()));
							String formid = "form" + t;
			%>
			<form id=<%=formid%> method="post">
				<table class="favoriteTable" border="0" cellpadding="8">
					<tr class="title">
						<td align="center" width="100px">
						<a href=<%="favoriteItemInfo?favoriteItemId=" + itemId
								+ "&pageSize=" + pageSize + "&nowPage="
								+ nowPage + "&favoriteUserId="+userId%>
							target="_blank"><%=item.getItemName()%></a></td>
						<td align="center" width="100px">￥<%=marketPrice%></td>
						<td align="center" width="100px">￥<%=priceAfterDiscount %></td>
						<td align="center" width="100px">￥<%=save%></td>
						<td align="center" width="100px">
							<input type="hidden"  name="favoriteId" value=<%=favoriteId%>> 
							<input type="hidden" name="favoriteUserId" value=<%=favorite.getFavoriteUserId()%>> 
							<input type="hidden" name="favoriteItemId" value=<%=favorite.getFavoriteItemId()%>> 
							<input type="hidden" name="nowPage" value=<%=nowPage%>> 
							<input type="hidden" name="pageSize" value=<%=pageSize%>> 
							<input type="hidden" name="userId" value=<%=userId%>> 
							<input type="hidden" name="cartItemId" value=<%=favorite.getFavoriteItemId()%>>
						</td>
						<td align="center" width="70px"><input type="image"
							src="images/src/button/delete.png"
							onClick="<%=formid%>.action='deleteFavItemAction';" /></td>
						<td align="center" width="70px"><input type="image"
							src="images/src/button/purchase.png"
							onClick="<%=formid%>.action='addCartAction';" /></td>
					</tr>
				</table>
			</form>
			<%
				t++;
						}
					}
			%>
			<div class="pagechoose" align="center">
				<%
					if (totalPageNum == 0) {
				%>
				<a>您的收藏夹还未添加任何商品</a>
				<%
					} else {
				%>
				<%
					if (nowPage - 1 != 0) {
				%>
				<a
					href=<%="displayFavAction?nowPage=" + (nowPage - 1)
								+ "&favoriteUserId=" + userId%>>上一页</a>
				<%
					}
				%>
				<%
					for (int i = 0; i < 4; i++) {
				%>
				<%
					if (nowPage - 4 + i > 0) {
				%>
				<a
					href=<%="displayFavAction?nowPage="
									+ (nowPage - 4 + i) + "&favoriteUserId="
									+ userId%>><%=(nowPage - 4 + i)%></a>
				<%
					}
				%>
				<%
					}
				%>
				<a style="text-decoration: underline;"><%=nowPage%></a>
				<%
					for (int i = 0; i < 3; i++) {
				%>
				<%
					if (nowPage + i + 1 <= totalPageNum) {
				%>
				<a
					href=<%="displayFavAction?nowPage="
									+ (nowPage + i + 1) + "&favoriteUserId="
									+ userId%>><%=(nowPage + i + 1)%></a>
				<%
					}
				%>
				<%
					}
				%>
				<%
					if (nowPage + 1 <= totalPageNum) {
				%>
				<a
					href=<%="displayFavAction?nowPage=" + (nowPage + 1)
								+ "&favoriteUserId=" + userId%>>下一页</a>
				<%
					}
				%>
				<%
					}
				%>
				<%
					}
				%>
			</div>
		</div>
	</div>


	<jsp:include page="footer.jsp" flush="true"></jsp:include>
</body>
</html>
